/**
 * author:Administrator
 * date:2015/7/27
 * desc:TODO
 */

"use strict";

let mongoose = require('mongoose');
let Schema = mongoose.Schema;
let RoleSchema = new Schema({
    name: {type: String, index: true, unique: true},
    pUniqueName: [String], // permission unique name
    createdAt: {type: Date, default: Date.now},
    updatedAt: Date
});

RoleSchema.pre('save', function (next) {
    if (!this.updatedAt) {
        this.updatedAt = new Date();
    }
    next();
});

// 指定collection name，默认是复数
var permission = mongoose.model('role', RoleSchema, 'role');
exports = module.exports = permission;